<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/jsp/comm_css_include.jsp"%>
<!-- jqgrid-->
<link href="${basePath}/css/plugins/jqgriddemo/css/ui.jqgrid-bootstrap.min.css" rel="stylesheet" />
<!doctype html>
<html>
<head>
</head>
<body class="gray-bg">
<div class="container creditbody">
	<div class="iboxtitle">
		<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;贷中业务>GPS加装</span>
		<a href="javascript:void(0)"></a>
	</div>
	<div class="ibox-content ibox-con">
		<%@include file="/jsp/comm_yw_info_include.jsp"%>
		<div class="business-manwife">GPS信息</div>
        <form class="form-horizontal" id="commentForm"> 
        	<input id="busiId" name="busiId" type="hidden" />
        	<input id="customerId" name="customerId" type="hidden" />
			<div class="insert-gps" id="insert-gps"> 
			</div>	
		</form>
		<div class="business-manwife">附件信息</div>
		<div class="padding-nono">
			<div class="zx-addimg">
				<ul id="GPS_ZI_LIAO">
					<li class="firstMuliUploadButton zx-upimg"><img
						src="${basePath}/img/shangchuanzhaopian.png" width="110px"
						height="110px" class="zx-imgPre" style="display: block;" />
						<div class="img-layer">
							<div></div>
							<span filelabelLabelSpan="${attachmentLabelNames.GPS_ZI_LIAO }">${attachmentLabelNameValues.GPS_ZI_LIAO }</span>
						</div> 
						<a href="javascript:;" class="file" onclick="uploadFileClicked(this,'img');" modeId="${modeIDTypeNames.GPSJIAZHUANG }" ulId="GPS_ZI_LIAO" customLabel="true" isAdd="true" fileLabelLi="${attachmentLabelNames.GPS_ZI_LIAO }" defaltLabelNameLi="${attachmentLabelNameValues.GPS_ZI_LIAO }" subId="" >
					</a></li>
				</ul>
			</div>
		</div>
</div>	
	<!-- public quote -->
    <%@include file="/jsp/comm_js_include.jsp"%>

    <!-- layerDate plugin javascript -->
    <script src="${basePath}/js/plugins/layer/laydate/laydate.js"></script>
    
    <!-- 文件上传 -->
 	<%@include file="/jsp/common_fileupload_multi_include.jsp"%>
    <!--
    	作者：zhangpp
    	时间：2017-04-06
    	描述：js
    -->
    <script type="text/javascript">
    $(function(){
    	$('#busiId').val($.getUrlData("busiId"));
    	$('#customerId').val($.getUrlData("cusId"));
    	var num = $.getUrlData("numGps");
    	getGPSCompanyDic();
		getNumgps(num);
		getGpsList();
		getData();
	 });
    var getGpsList=function(){
    	var data={};
    	data.busiId=$.getUrlData("busiId");
    	$.dpAjax({
    		url:'${basePath}/DzGpsController/list',
    		data:data,
   			success: function(datas){
    			  if(datas.flag == "100100")
				  {
    				  var data=datas.result.rows;
    				  if(data.length>0){
    					  for(var i=0;i<data.length;i++){
		    				  $("#btnsave"+i).hide();
		    				  $("#timeInstall"+i).val(data[i].timeInstall);
		    				  $("#operatorInstall"+i).val(data[i].operatorInstall);
// 		    				  $("#companyGps"+num+" option:selected").val(); 
		    				  $("#modelGps"+i).val(data[i].modelGps);
		    				  $("#keyGps"+i).val(data[i].keyGps);
		    				  $("#lifetimeGps"+i).val(data[i].lifetimeGps);
		    				  $("#locationInstall"+i).val(data[i].locationInstall);
    					  }
    				  }
					  layer.msg('执行成功！', {icon: 6});
					  return;
				  }
				  if(datas.flag == "100200")
                  {
					  $.fn.showDatas({"datas":datas});
                	  return;
                  }
                }
    	});
    }
    
  //展示数据
    function getData(){
    	showAttentment($.getUrlData('busiId'), null, '${modeIDTypeNames.GPSJIAZHUANG }');
    }
    
    function getGPSCompanyDic(){
    	$.dpAjax({
	    	url:'${basePath}/DataDictionaryController/getEnableList',
 			data:{
 				"parentValue":"GPSCompany"
 			},
 			success: function(datas){
	 					 var result = datas.result.rows;
						  var programme_sel=[];
					      for(var i=0;i<result.length;i++){
					          var programme = result[i];
					          programme_sel.push('<option value="'+programme.value+'">'+programme.name+'</option>')
					      }
						     $(".companyGps").html(programme_sel.join(' '));
              }
	    });
    }
    
    function getNumgps(num){
    	var html="";
    	for(var i=0; i<num; i++){
    		html +='<div class="business-padding"><button id="btnsave'+i+'"  class="btn dpbtn_blue" type="button" onclick="dosave('+i+');">保存</button>'
				+'<table cellpadding="0" cellspacing="0" border="0" class="buyinfor-table">'
				+'<tr>'
				+'<td align="right">'
				+'<label class="control-label np">安装时间：</label>'
				+'</td>'
				+'<td>'
				+'<input id="timeInstall'+i+'" name="timeInstall" class="smallicontm form-control" placeholder="安装时间" required="required" onclick="laydate(this)" />'
				+'</td>'
				+'<td align="right">'
				+'<label class="control-label np">安装人：</label>'
				+'</td>'
				+'<td>'
				+'<input id="operatorInstall'+i+'" required="required" name="operatorInstall" placeholder="安装人" class="form-control" />'
				+'</td>'
				+'</tr>'
				+'<tr>'	
				+'<td align="right">'
				+'<label class="control-label np">所属公司：</label>'
				+'</td>'
				+'<td>'
				+'<select id="companyGps'+i+'" name="companyGps" class="select-control companyGps" ></select>'
				+'</td>'
				+'<td align="right">'
				+'<label class="control-label np">设备型号：</label>'
				+'</td>'
				+'<td>'
				+'<input id="modelGps'+i+'" name="modelGps" class="form-control" placeholder="设备型号" />'
				+'</td>'
				+'</tr>'
				+'<tr>'
				+'<td align="right">'
				+'<label class="control-label np">设备码：</label>'
				+'</td>'
				+'<td>'
				+'<input id="keyGps'+i+'" name="keyGps"  class="form-control" placeholder="GPS唯一编码" required="" aria-required="true"/>'
				+'</td>'
				+'<td align="right">'
				+'<label class="control-label np">预计寿命(月)：</label>'
				+'</td>'
				+'<td>'
				+'<input id="lifetimeGps'+i+'" name="lifetimeGps" placeholder="预计寿命" class="form-control" value="0"  type="number" min="0"  aria-required="true"/>'
				+'</td>'
				+'</tr>'
				+'<tr>'
				+'<td align="right">'
				+'<label class="control-label np">安装位置：</label>'
				+'</td>'
				+'<td colspan="3">'
				+'<input id="locationInstall'+i+'" name="locationInstall" class="form-control" placeholder="安装位置" required="required"/>'
				+'</td>'
				+'</tr>'
				+'</table>'
				+'</div>';
    	}
    	$("#insert-gps").append(html);
    	
    }
    
    
    
	var allocation=function(data,num){
		layer.confirm('是否确认执行操作？操作人：<span style="color:#BD1723;">${current_user_key.uname}</span>', {
	    	  btn: ['确定','取消'] //按钮
	    	}, function(){
    		layer.closeAll();
			$.dpAjax({
	    		url:'${basePath}/DzGpsController/save',
	    		data:data,
	   			success: function(datas){
	   				$("#btnsave"+num).hide();
					  layer.msg('执行成功！', {icon: 6});
					  return;
	            }
	    	});
	    })	
	}
	
   var dosave=function(num){
		data={};
		data.timeInstall=$("#timeInstall"+num).val();
		data.operatorInstall=$("#operatorInstall"+num).val();
		data.companyGps=$("#companyGps"+num+" option:selected").val(); 
		data.modelGps=$("#modelGps"+num).val();
		data.keyGps=$("#keyGps"+num).val();
		data.lifetimeGps=$("#lifetimeGps"+num).val();
		data.locationInstall=$("#locationInstall"+num).val();
		data.busiId=$.getUrlData("busiId");
		data.cusId=$.getUrlData("cusId");
		data.idGpsList=$.getUrlData("idGpsList");
		this.allocation(data,num);
   }
   
   var formateStringDate=function(sDate1){
    	if(!sDate1 || sDate1 == ''){
    		return '-';
    	}
    	var aDate  =  sDate1.substring(0,sDate1.lastIndexOf(" "))
    	return aDate;
    }
    </script>
</body>
</html>
